import request from '@/utils/request'
import {encodeParams} from '@/utils'

//普通运营账号列表
export function getUserList(data) {
  return request({
    url: `/api/user?${encodeParams(data)}`,
    method: 'GET',
    data
  })
}

//获取账号信息
export function getUserInfo(data) {
  return request({
    url: '/api/user/findUser',
    method: 'POST',
    data
  })
}

//获取全部角色
export function getRoleAll() {
  return request({
    url: '/api/role/getAll',
    method: 'GET'
  })
}

// 创建用户/编辑/重置密码
export function createUser(data, type) {
  let _url
  switch (type) {
    case 'add':
      _url = '/api/user/create'
      break
    case 'edit':
      _url = '/api/user/update'
      break
    case 'reset':
      _url = '/api/user/resetPassword'
      break

  }
  return request({
    url: _url,
    method: 'POST',
    data
  })
}

//删除角色
export function deleteUser(id) {
  return request({
    url: `/api/user/delete/${id}`,
    method: 'GET'
  })
}

//更改用户状态
export function changeUserStatus(id, enabled) {
  return request({
    url: `/api/user/enable/${id}/${enabled}`,
    method: 'GET'
  })
}


//重置密码(S端重置密码)
export function resetPassword(userId) {
  return request({
    url: `/api/user/S/${userId}/resetPassword`,
    method: 'PUT',
  })
}


export default {
  getUserList,
  getUserInfo,
  getRoleAll,
  createUser,
  deleteUser,
  changeUserStatus
}
